package com.ssy.lingxi.product.entity;

import com.ssy.lingxi.product.handler.converter.JpaJsonToMapConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashMap;

/**
 * 品牌实体类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/28
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_brand", indexes = {@Index(name = "product_brand_member_id_member_role_id_idx", columnList = "memberId,memberRoleId"),
        @Index(name = "product_brand_name_idx", columnList = "name"),
        @Index(name = "product_brand_status_idx", columnList = "status"),
        @Index(name = "product_brand_is_enable_idx", columnList = "isEnable")})
public class Brand implements Serializable {
    private static final long serialVersionUID = 386808695515968383L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="brand_seq")
    @SequenceGenerator(sequenceName="product_brand_seq", name="brand_seq",allocationSize = 1)
    private Long id;

    /**
     * 品牌名称
     */
    @Column(columnDefinition = "varchar(20)", nullable = false)
    private String name;

    /**
     * 品牌logo
     */
    @Column(columnDefinition = "varchar(250)", nullable = false)
    private String logoUrl;

    /**
     * 申请时间
     */
    @Column(columnDefinition = "int8")
    private Long applyTime;

    /**
     * 审核状态: 1-待提交审核, 2-待审核, 3-审核不通过, 4-审核通过
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer status = 1;

    /**
     * 审核时间
     */
    @Column(columnDefinition = "int8")
    private Long checkTime;

    /**
     * 是否有效
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isEnable = false;

    /**
     * 证明材料
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition="jsonb")
    private HashMap<String,Object> proveUrl;

    /**
     * 会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 会员角色id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberRoleId;

    /**
     * 会员角色名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberRoleName;

    /**
     * 用户id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long userId;

    /**
     * 用户名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String userName;

    /**
     * 修改之前的品牌id
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="sourceBrandId",referencedColumnName = "id")
    private Brand sourceBrand;

    /**
     * 修改之前的品牌名称
     */
    @Column(columnDefinition = "varchar(20)")
    private String sourceBrandName;

    /**
     * 审核类型: 1-会员审核, 2-平台审核
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer type = 1;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();
}
